package com.app.outdoor.pojo;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import ReadWriteXML.XMLBuilder;

public class NguoiDungPOJO {
	private int id;
	private String tenDangNhap;
	private String matKhau;
	private String deviceID;
	private long lastRequest;
	public String getTenDangNhap() {
		return tenDangNhap;
	}
	public void setTenDangNhap(String tenDangNhap) {
		this.tenDangNhap = tenDangNhap;
	}
	public String getMatKhau() {
		return matKhau;
	}
	public void setMatKhau(String matKhau) {
		this.matKhau = matKhau;
	}
	public String getDeviceID() {
		return deviceID;
	}
	public void setDeviceID(String deviceID) {
		this.deviceID = deviceID;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public long getLastRequest() {
		return lastRequest;
	}
	public void setLastRequest(long lastRequest) {
		this.lastRequest = lastRequest;
	}
	public Element createContactXMLElement(Document doc){
		Element element=doc.createElement("NguoiDung");
		element.setAttribute("TenDangNhap", tenDangNhap);
		element.setAttribute("ID", this.id+"");
		element.setAttribute("LastRequest", this.lastRequest+"");
		return element;
	}
	public boolean parse(String xml){
		boolean rs=false;
		try {
			Document doc=XMLBuilder.loadXMLFromString(xml);
			NodeList nodelist=doc.getElementsByTagName("NguoiDung");
			if(nodelist!=null){
				Element element=(Element) nodelist.item(0);
				this.id=Integer.parseInt(element.getAttribute("ID"));
				this.tenDangNhap=element.getAttribute("TenDangNhap");
				this.lastRequest=Long.parseLong(element.getAttribute("LastRequest"));
				rs=true;
			}
		} catch (Exception e) {
			rs= false;
		}
		return rs;
	}
}
